<template>
  <div class="execution">
    <basic-container>
      <el-tabs v-model="activeName" @tab-click="handleClickTab">
        <el-tab-pane label="待审核" name="first"></el-tab-pane>
        <el-tab-pane label="已通过" name="second"></el-tab-pane>
        <el-tab-pane label="已驳回" name="third"></el-tab-pane>

        <el-card class="filter-container" shadow="never">
          <div style="margin-top: 10px">
            <el-form :inline="true" size="small" label-width="140px">
              <el-form-item label="店铺名称：">
                <el-select v-model="listQuery.storeId" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.storeId"
                    :label="item.storeName"
                    :value="item.storeId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button @click="getList" type="primary" size="small"
                  >查询结果</el-button
                >
                <el-button @click="handleResetSearch" size="small">
                  重置
                </el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-card>

        <div class="table-container">
          <el-table
            border
            :header-cell-style="{ color: '#4D4D4D', background: '#fafafa' }"
            :data="list"
            v-loading="listLoading"
          >
            <el-table-column label="店铺名称" align="center">
              <template slot-scope="scope">{{ scope.row.storeName }}</template>
            </el-table-column>

            <el-table-column label="名称" align="center">
              <template slot-scope="scope">{{ scope.row.name }}</template>
            </el-table-column>

            <el-table-column label="等级" align="center">
              <template slot-scope="scope">
                <p>{{ scope.row.level }}</p>
              </template>
            </el-table-column>

            <el-table-column label="是否显示" align="center">
              <template slot-scope="scope">
                <p>{{ scope.row.isShow }}</p>
              </template>
            </el-table-column>

            <el-table-column label="APP图标" align="center">
              <template slot-scope="scope">
                <img
                  :src="scope.row.appPic"
                  style="width: 100px; height: 100px"
                />
              </template>
            </el-table-column>

            <el-table-column label="小程序图标" align="center">
              <template slot-scope="scope">
                <img
                  :src="scope.row.appletsPic"
                  style="width: 100px; height: 100px"
                />
              </template>
            </el-table-column>

            <el-table-column
              label="排序"
              align="center"
              prop="editName"
            ></el-table-column>

            <el-table-column
              v-if="listQuery.status !== 1"
              label="审核时间"
              align="center"
              prop="examineTime"
            ></el-table-column>

            <el-table-column
              label="操作人"
              align="center"
              prop="edit"
            ></el-table-column>

            <el-table-column
              v-if="listQuery.status === 3"
              label="驳回原因"
              align="center"
              prop="rejectionReason"
            ></el-table-column>

            <el-table-column
              label="操作时间"
              align="center"
              prop="editTime"
            ></el-table-column>
            <el-table-column label="操作" min-width="200" align="center">
              <template slot-scope="scope">
                <el-button
                  size="small"
                  type="text"
                  @click="handleSee(scope.$index, scope.row)"
                  >查看
                </el-button>

                <el-button
                  size="small"
                  v-if="listQuery.status === 1"
                  @click="handleExamine(scope.$index, scope.row)"
                  type="text"
                  icon="el-icon-edit"
                  >审核</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.size"
            :page-sizes="[5, 10, 15]"
            :current-page.sync="listQuery.current"
            :total="total"
          >
          </el-pagination>
        </div>
      </el-tabs>
    </basic-container>
  </div>
</template>
<script>
import "@/styles/index.scss";
import { getSortList } from "@/api/pms/index";
import { getStore } from "@/api/rms/rmsstore";

const defaultListQuery = {
  current: 1,
  size: 10,
  status: 1,
  storeId: null,
};

export default {
  data() {
    return {
      activeName: "first",
      list: [],
      total: 0,
      listLoading: true,
      listQuery: Object.assign({}, defaultListQuery),
      tabValueMap: {
        first: 1,
        second: 2,
        third: 3,
      },
      options: [],
    };
  },
  created() {
    this.getList();
    this.getStoreList();
  },
  methods: {
    handleClickTab(tab, event) {
      this.listQuery.status = this.tabValueMap[this.activeName];
      this.listQuery.storeId = "";
      this.listQuery.current = 1;
      this.getList();
      this.getStoreList();
    },
    getStoreList() {
      getStore({ status: this.listQuery.status }).then((res) => {
        this.options = res.data.data;
      });
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      getSortList(this.listQuery).then((response) => {
        this.listLoading = false;
        this.list = response.data.data.records;
        this.total = response.data.data.total;
      });
    },
    handleResetSearch() {
      this.listQuery.storeId = "";
      this.getList();
    },
    handleSee(index, row) {
      this.$router.push({
        path: "/pms/produetSort/see",
        query: { id: row.id },
      });
    },
    handleExamine(index, row) {
      this.$router.push({
        path: "/pms/produetSort/examine",
        query: { id: row.id },
      });
    },
  },
};
</script>